<template><div><h2 id="常用参数注解" tabindex="-1"><a class="header-anchor" href="#常用参数注解"><span>常用参数注解</span></a></h2>
<ul>
<li>@RequestParam         获取请求的查询参数 按照变量名进行映射</li>
<li>@PathVariable         获取请求的路径参数 按照变量名进行映射</li>
<li>@RequestBody          获取请求体的JSON数据 直接映射</li>
<li>@RequestHeader(&quot;key&quot;) 获取请求头中指定key的值</li>
<li>@CookieValue(&quot;key&quot;)   获取请求中cookie中指定key的值</li>
<li>@RequestPart          获取上传的文件(MultipartFile)</li>
</ul>
<h2 id="http报文" tabindex="-1"><a class="header-anchor" href="#http报文"><span>http报文</span></a></h2>
<p><img src="@source/notes/每周一学/1.第一周学习/http报文.png" alt="图片加载失败">
HTTP请求报文（也称请求消息）由请求行（request line）、请求头（header）、空行和请求数据(也称请求体)4个部分组成
<img src="@source/notes/每周一学/1.第一周学习/http请求报文.png" alt="图片加载失败"></p>
<h3 id="http1-1现常用请求方式有" tabindex="-1"><a class="header-anchor" href="#http1-1现常用请求方式有"><span>http1.1现常用请求方式有:</span></a></h3>
<ol>
<li>
<p>GET</p>
<p>请求数据</p>
</li>
<li>
<p>POST</p>
<p>提交数据</p>
</li>
<li>
<p>PUT</p>
<p>修改指定数据</p>
</li>
<li>
<p>DELETE</p>
<p>删除指定数据</p>
</li>
<li>
<p>TRANCE</p>
<p>回显服务器收到的请求，主要用来测试</p>
</li>
<li>
<p>CONNECT</p>
<p>将连接改为管道方式的代理服务器？</p>
</li>
<li>
<p>OPTION</p>
<p>允许客户端查看服务器的性能</p>
</li>
<li>
<p>HEAD</p>
<p>类似于get请求,只不过返回的响应没有具体的内容,用于获取报头，一般查看某个页面状态的时候，不需要传输页面内容，比较高效</p>
</li>
<li>
<p>PATCH</p>
<p>修改指定数据的部分数据</p>
</li>
</ol>
<h3 id="请求头常见参数" tabindex="-1"><a class="header-anchor" href="#请求头常见参数"><span>请求头常见参数</span></a></h3>
<p><img src="@source/notes/每周一学/1.第一周学习/http请求体常见参数.png" alt="图片加载失败"></p>
<h3 id="content-type" tabindex="-1"><a class="header-anchor" href="#content-type"><span>Content-Type</span></a></h3>
<p>请求(返回)报文中的请求头中有一个字段Content-Type来表示请求体(返回实体)中数据的格式</p>
<ol>
<li>text/html</li>
</ol>
<p>请求体是个html文档，浏览器会把其渲染成为个页面</p>
<div class="language-java line-numbers-mode" data-highlighter="shiki" data-ext="java" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#E06C75">GET </span><span style="color:#56B6C2">/</span><span style="color:#E5C07B">index</span><span style="color:#ABB2BF">.</span><span style="color:#E5C07B">html</span><span style="color:#E06C75"> HTTP</span><span style="color:#56B6C2">/</span><span style="color:#D19A66">1.1</span></span>
<span class="line"><span style="color:#E06C75">Host</span><span style="color:#C678DD">:</span><span style="color:#E5C07B"> example</span><span style="color:#ABB2BF">.</span><span style="color:#E5C07B">com</span></span>
<span class="line"><span style="color:#E06C75">Content</span><span style="color:#56B6C2">-</span><span style="color:#E06C75">Type</span><span style="color:#C678DD">:</span><span style="color:#E06C75"> text</span><span style="color:#56B6C2">/</span><span style="color:#E06C75">html</span></span>
<span class="line"></span>
<span class="line"><span style="color:#56B6C2">&#x3C;</span><span style="color:#E06C75">html</span><span style="color:#56B6C2">></span></span>
<span class="line"><span style="color:#56B6C2">&#x3C;</span><span style="color:#E06C75">body</span><span style="color:#56B6C2">></span></span>
<span class="line"><span style="color:#E5C07B">Hello</span><span style="color:#E5C07B"> World</span></span>
<span class="line"><span style="color:#56B6C2">&#x3C;/</span><span style="color:#E06C75">body</span><span style="color:#56B6C2">></span></span>
<span class="line"><span style="color:#56B6C2">&#x3C;/</span><span style="color:#E06C75">html</span><span style="color:#56B6C2">></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ol start="2">
<li>application/json</li>
</ol>
<p>json数据格式</p>
<div class="language-java line-numbers-mode" data-highlighter="shiki" data-ext="java" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#E06C75">POST </span><span style="color:#56B6C2">/</span><span style="color:#E06C75">api</span><span style="color:#56B6C2">/</span><span style="color:#E06C75">users HTTP</span><span style="color:#56B6C2">/</span><span style="color:#D19A66">1.1</span></span>
<span class="line"><span style="color:#E06C75">Host</span><span style="color:#C678DD">:</span><span style="color:#E5C07B"> example</span><span style="color:#ABB2BF">.</span><span style="color:#E5C07B">com</span></span>
<span class="line"><span style="color:#E06C75">Content</span><span style="color:#56B6C2">-</span><span style="color:#E06C75">Type</span><span style="color:#C678DD">:</span><span style="color:#E06C75"> application</span><span style="color:#56B6C2">/</span><span style="color:#E06C75">json</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E06C75">{</span></span>
<span class="line"><span style="color:#98C379">  "name"</span><span style="color:#C678DD">:</span><span style="color:#98C379"> "Jane Smith"</span><span style="color:#ABB2BF">,</span></span>
<span class="line"><span style="color:#98C379">  "age"</span><span style="color:#C678DD">:</span><span style="color:#D19A66"> 30</span><span style="color:#ABB2BF">,</span></span>
<span class="line"><span style="color:#98C379">  "email"</span><span style="color:#C678DD">:</span><span style="color:#98C379"> "jane@example.com"</span></span>
<span class="line"><span style="color:#E06C75">}</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ol start="3">
<li>application/x-www-form-urlencoded</li>
</ol>
<p>html表单默认的content-type类型，表示数据用键值对的形式进行编码</p>
<div class="language-java line-numbers-mode" data-highlighter="shiki" data-ext="java" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#E06C75">POST </span><span style="color:#56B6C2">/</span><span style="color:#E06C75">login HTTP</span><span style="color:#56B6C2">/</span><span style="color:#D19A66">1.1</span></span>
<span class="line"><span style="color:#E06C75">Host</span><span style="color:#C678DD">:</span><span style="color:#E5C07B"> example</span><span style="color:#ABB2BF">.</span><span style="color:#E5C07B">com</span></span>
<span class="line"><span style="color:#E06C75">Content</span><span style="color:#56B6C2">-</span><span style="color:#E06C75">Type</span><span style="color:#C678DD">:</span><span style="color:#E06C75"> application</span><span style="color:#56B6C2">/</span><span style="color:#E06C75">x</span><span style="color:#56B6C2">-</span><span style="color:#E06C75">www</span><span style="color:#56B6C2">-</span><span style="color:#E06C75">form</span><span style="color:#56B6C2">-</span><span style="color:#E06C75">urlencoded</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E06C75">username</span><span style="color:#56B6C2">=</span><span style="color:#E06C75">johndoe</span><span style="color:#56B6C2">&#x26;</span><span style="color:#E06C75">password</span><span style="color:#56B6C2">=</span><span style="color:#D19A66">123456</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ol start="4">
<li>multipart/form-data</li>
</ol>
<p>通常表示表单数据中包含文件上传，在请求体中，数据会被拆分成多个部分，每个部分应该包含自己独立的头部信息,使用boundary来表示数据的分割符</p>
<div class="language-java line-numbers-mode" data-highlighter="shiki" data-ext="java" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#E06C75">POST </span><span style="color:#56B6C2">/</span><span style="color:#E06C75">upload HTTP</span><span style="color:#56B6C2">/</span><span style="color:#D19A66">1.1</span></span>
<span class="line"><span style="color:#E06C75">Host</span><span style="color:#C678DD">:</span><span style="color:#E5C07B"> example</span><span style="color:#ABB2BF">.</span><span style="color:#E5C07B">com</span></span>
<span class="line"><span style="color:#E06C75">Content</span><span style="color:#56B6C2">-</span><span style="color:#E06C75">Type</span><span style="color:#C678DD">:</span><span style="color:#E06C75"> multipart</span><span style="color:#56B6C2">/</span><span style="color:#E06C75">form</span><span style="color:#56B6C2">-</span><span style="color:#E06C75">data</span><span style="color:#ABB2BF">;</span><span style="color:#E06C75"> boundary</span><span style="color:#56B6C2">=</span><span style="color:#ABB2BF">----</span><span style="color:#E5C07B">WebKitFormBoundary7MA4YWxkTrZu0gW</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ABB2BF">------</span><span style="color:#E5C07B">WebKitFormBoundary7MA4YWxkTrZu0gW</span></span>
<span class="line"><span style="color:#E06C75">Content</span><span style="color:#56B6C2">-</span><span style="color:#E06C75">Disposition</span><span style="color:#C678DD">:</span><span style="color:#E06C75"> form</span><span style="color:#56B6C2">-</span><span style="color:#E06C75">data</span><span style="color:#ABB2BF">;</span><span style="color:#E06C75"> name</span><span style="color:#56B6C2">=</span><span style="color:#98C379">"file"</span><span style="color:#ABB2BF">;</span><span style="color:#E06C75"> filename</span><span style="color:#56B6C2">=</span><span style="color:#98C379">"example.txt"</span></span>
<span class="line"><span style="color:#E06C75">Content</span><span style="color:#56B6C2">-</span><span style="color:#E06C75">Type</span><span style="color:#C678DD">:</span><span style="color:#E06C75"> text</span><span style="color:#56B6C2">/</span><span style="color:#E06C75">plain</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ABB2BF">...</span><span style="color:#E5C07B">file</span><span style="color:#E06C75"> content here</span><span style="color:#ABB2BF">...</span></span>
<span class="line"><span style="color:#ABB2BF">------</span><span style="color:#E06C75">WebKitFormBoundary7MA4YWxkTrZu0gW</span><span style="color:#ABB2BF">--</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ol start="5">
<li>text/plain</li>
</ol>
<p>表示纯文本,没有特殊意义的标志</p>
<div class="language-java line-numbers-mode" data-highlighter="shiki" data-ext="java" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#E06C75">POST </span><span style="color:#56B6C2">/</span><span style="color:#E06C75">text HTTP</span><span style="color:#56B6C2">/</span><span style="color:#D19A66">1.1</span></span>
<span class="line"><span style="color:#E06C75">Host</span><span style="color:#C678DD">:</span><span style="color:#E5C07B"> example</span><span style="color:#ABB2BF">.</span><span style="color:#E5C07B">com</span></span>
<span class="line"><span style="color:#E06C75">Content</span><span style="color:#56B6C2">-</span><span style="color:#E06C75">Type</span><span style="color:#C678DD">:</span><span style="color:#E06C75"> text</span><span style="color:#56B6C2">/</span><span style="color:#E06C75">plain</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E06C75">Hello</span><span style="color:#ABB2BF">,</span><span style="color:#E06C75"> World</span><span style="color:#56B6C2">!</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ol start="6">
<li>application/xml</li>
</ol>
<p>表示xml格式</p>
<div class="language-java line-numbers-mode" data-highlighter="shiki" data-ext="java" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#E06C75">POST </span><span style="color:#56B6C2">/</span><span style="color:#E06C75">api</span><span style="color:#56B6C2">/</span><span style="color:#E06C75">users HTTP</span><span style="color:#56B6C2">/</span><span style="color:#D19A66">1.1</span></span>
<span class="line"><span style="color:#E06C75">Host</span><span style="color:#C678DD">:</span><span style="color:#E5C07B"> example</span><span style="color:#ABB2BF">.</span><span style="color:#E5C07B">com</span></span>
<span class="line"><span style="color:#E06C75">Content</span><span style="color:#56B6C2">-</span><span style="color:#E06C75">Type</span><span style="color:#C678DD">:</span><span style="color:#E06C75"> application</span><span style="color:#56B6C2">/</span><span style="color:#E06C75">xml</span></span>
<span class="line"></span>
<span class="line"><span style="color:#56B6C2">&#x3C;</span><span style="color:#E06C75">user</span><span style="color:#56B6C2">></span></span>
<span class="line"><span style="color:#56B6C2">  &#x3C;</span><span style="color:#E06C75">name</span><span style="color:#56B6C2">></span><span style="color:#E5C07B">John</span><span style="color:#E5C07B"> Doe</span><span style="color:#56B6C2">&#x3C;/</span><span style="color:#E06C75">name</span><span style="color:#56B6C2">></span></span>
<span class="line"><span style="color:#56B6C2">  &#x3C;</span><span style="color:#E06C75">email</span><span style="color:#56B6C2">></span><span style="color:#E06C75">john</span><span style="color:#ABB2BF">@</span><span style="color:#E5C07B">example</span><span style="color:#ABB2BF">.</span><span style="color:#E5C07B">com</span><span style="color:#56B6C2">&#x3C;/</span><span style="color:#E06C75">email</span><span style="color:#56B6C2">></span></span>
<span class="line"><span style="color:#56B6C2">&#x3C;/</span><span style="color:#E06C75">user</span><span style="color:#56B6C2">></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="requestparam" tabindex="-1"><a class="header-anchor" href="#requestparam"><span>@RequestParam</span></a></h3>
<p>处理http请求报文中所有键值对的数据，包括报文中协议行的键值对，以及在请求体中content-type设置为application/x-www-form-urlencoded的键值对，通过参数名称进行匹配</p>
<h3 id="pathvariable" tabindex="-1"><a class="header-anchor" href="#pathvariable"><span>@PathVariable</span></a></h3>
<p>处理http请求报文中协议行的数据，通过规定url模板串的形式进行参数绑定</p>
<h3 id="requestbody" tabindex="-1"><a class="header-anchor" href="#requestbody"><span>@RequestBody</span></a></h3>
<p>处理http请求报文中所有content-type声明为json的数据</p>
<h3 id="requestheader-key" tabindex="-1"><a class="header-anchor" href="#requestheader-key"><span>@RequestHeader(&quot;key&quot;)</span></a></h3>
<p>获取http请求报文中请求头中key的值</p>
<h3 id="cookievalue-key" tabindex="-1"><a class="header-anchor" href="#cookievalue-key"><span>@CookieValue(&quot;key&quot;)</span></a></h3>
<p>获取http请求报文中请求头中cookie的key的值</p>
<h3 id="requestpart" tabindex="-1"><a class="header-anchor" href="#requestpart"><span>@RequestPart</span></a></h3>
<p>获取http请求报文中有content-type声明为multipart的数据</p>
<h2 id="补充" tabindex="-1"><a class="header-anchor" href="#补充"><span>补充</span></a></h2>
<h3 id="get和post的区别" tabindex="-1"><a class="header-anchor" href="#get和post的区别"><span>GET和POST的区别</span></a></h3>
<ol>
<li>传输数据的方式不同
GET请求的数据在地址栏传参，如果数据是英文字母/数字，原样发送，空格转换为+，中文或者其他字符使用base64加密，POST请求的数据放在请求体中。</li>
<li>传输数据的大小不一样
本身http协议并没有对传输数据大小进行限制，但是GET请求会受到浏览器url长度的限制，POST请求会受到web服务器接收请求体数据大小的限制</li>
<li>POST比GET安全性更高
GET请求所有的数据都会放在协议头上，所以一般都会被明文观看到,POST请求一般会安全点，但是如果考虑安全性一般使用https协议，https协议使用ssl协议进行加密</li>
</ol>
<h2 id="实验" tabindex="-1"><a class="header-anchor" href="#实验"><span>实验</span></a></h2>
<p>为什么在get请求中,不加@RequestParam注解也可以正常工作？
留个底,https://blog.csdn.net/as513385/article/details/93512699</p>
<blockquote>
<p>参考:https://blog.csdn.net/sunyctf/article/details/129002163</p>
</blockquote>
</div></template>


